//===----------------------------------------------------------------------===//
//
// This source file is part of the Soto for AWS open source project
//
// Copyright (c) 2017-2024 the Soto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of Soto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

// THIS FILE IS AUTOMATICALLY GENERATED by https://github.com/soto-project/soto-codegenerator.
// DO NOT EDIT.

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
@_exported import SotoCore

/// Service object for interacting with AWS SSO service.
///
/// AWS IAM Identity Center (successor to AWS Single Sign-On) Portal is a web service that makes it easy for you to assign user access to IAM Identity Center resources such as the AWS access portal. Users can get AWS account applications and roles assigned to them and get federated into the application.  Although AWS Single Sign-On was renamed, the sso and identitystore API namespaces will continue to retain their original name for backward compatibility purposes. For more information, see IAM Identity Center rename.  This reference guide describes the IAM Identity Center Portal operations that you can call programatically and includes detailed information on data types and errors.  AWS provides SDKs that consist of libraries and sample code for various programming languages and platforms, such as Java, Ruby, .Net, iOS, or Android. The SDKs provide a convenient way to create programmatic access to IAM Identity Center and other AWS services. For more information about the AWS SDKs, including how to download and install them, see Tools for Amazon Web Services.
public struct SSO: AWSService {
    // MARK: Member variables

    /// Client used for communication with AWS
    public let client: AWSClient
    /// Service configuration
    public let config: AWSServiceConfig

    // MARK: Initialization

    /// Initialize the SSO client
    /// - parameters:
    ///     - client: AWSClient used to process requests
    ///     - region: Region of server you want to communicate with. This will override the partition parameter.
    ///     - partition: AWS partition where service resides, standard (.aws), china (.awscn), government (.awsusgov).
    ///     - endpoint: Custom endpoint URL to use instead of standard AWS servers
    ///     - middleware: Middleware chain used to edit requests before they are sent and responses before they are decoded 
    ///     - timeout: Timeout value for HTTP requests
    ///     - byteBufferAllocator: Allocator for ByteBuffers
    ///     - options: Service options
    public init(
        client: AWSClient,
        region: SotoCore.Region? = nil,
        partition: AWSPartition = .aws,
        endpoint: String? = nil,
        middleware: AWSMiddlewareProtocol? = nil,
        timeout: TimeAmount? = nil,
        byteBufferAllocator: ByteBufferAllocator = ByteBufferAllocator(),
        options: AWSServiceConfig.Options = []
    ) {
        self.client = client
        self.config = AWSServiceConfig(
            region: region,
            partition: region?.partition ?? partition,
            serviceName: "SSO",
            serviceIdentifier: "portal.sso",
            signingName: "awsssoportal",
            serviceProtocol: .restjson,
            apiVersion: "2019-06-10",
            endpoint: endpoint,
            serviceEndpoints: Self.serviceEndpoints,
            errorType: SSOErrorType.self,
            middleware: middleware,
            timeout: timeout,
            byteBufferAllocator: byteBufferAllocator,
            options: options
        )
    }


    /// custom endpoints for regions
    static var serviceEndpoints: [String: String] {[
        "af-south-1": "portal.sso.af-south-1.amazonaws.com",
        "ap-east-1": "portal.sso.ap-east-1.amazonaws.com",
        "ap-northeast-1": "portal.sso.ap-northeast-1.amazonaws.com",
        "ap-northeast-2": "portal.sso.ap-northeast-2.amazonaws.com",
        "ap-northeast-3": "portal.sso.ap-northeast-3.amazonaws.com",
        "ap-south-1": "portal.sso.ap-south-1.amazonaws.com",
        "ap-south-2": "portal.sso.ap-south-2.amazonaws.com",
        "ap-southeast-1": "portal.sso.ap-southeast-1.amazonaws.com",
        "ap-southeast-2": "portal.sso.ap-southeast-2.amazonaws.com",
        "ap-southeast-3": "portal.sso.ap-southeast-3.amazonaws.com",
        "ap-southeast-4": "portal.sso.ap-southeast-4.amazonaws.com",
        "ap-southeast-5": "portal.sso.ap-southeast-5.amazonaws.com",
        "ca-central-1": "portal.sso.ca-central-1.amazonaws.com",
        "ca-west-1": "portal.sso.ca-west-1.amazonaws.com",
        "cn-north-1": "portal.sso.cn-north-1.amazonaws.com.cn",
        "cn-northwest-1": "portal.sso.cn-northwest-1.amazonaws.com.cn",
        "eu-central-1": "portal.sso.eu-central-1.amazonaws.com",
        "eu-central-2": "portal.sso.eu-central-2.amazonaws.com",
        "eu-north-1": "portal.sso.eu-north-1.amazonaws.com",
        "eu-south-1": "portal.sso.eu-south-1.amazonaws.com",
        "eu-south-2": "portal.sso.eu-south-2.amazonaws.com",
        "eu-west-1": "portal.sso.eu-west-1.amazonaws.com",
        "eu-west-2": "portal.sso.eu-west-2.amazonaws.com",
        "eu-west-3": "portal.sso.eu-west-3.amazonaws.com",
        "il-central-1": "portal.sso.il-central-1.amazonaws.com",
        "me-central-1": "portal.sso.me-central-1.amazonaws.com",
        "me-south-1": "portal.sso.me-south-1.amazonaws.com",
        "sa-east-1": "portal.sso.sa-east-1.amazonaws.com",
        "us-east-1": "portal.sso.us-east-1.amazonaws.com",
        "us-east-2": "portal.sso.us-east-2.amazonaws.com",
        "us-gov-east-1": "portal.sso.us-gov-east-1.amazonaws.com",
        "us-gov-west-1": "portal.sso.us-gov-west-1.amazonaws.com",
        "us-west-1": "portal.sso.us-west-1.amazonaws.com",
        "us-west-2": "portal.sso.us-west-2.amazonaws.com"
    ]}



    // MARK: API Calls

    /// Returns the STS short-term credentials for a given role name that is assigned to the user.
    @Sendable
    @inlinable
    public func getRoleCredentials(_ input: GetRoleCredentialsRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> GetRoleCredentialsResponse {
        try await self.client.execute(
            operation: "GetRoleCredentials", 
            path: "/federation/credentials", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Returns the STS short-term credentials for a given role name that is assigned to the user.
    ///
    /// Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - accountId: The identifier for the AWS account that is assigned to the user.
    ///   - roleName: The friendly name of the role that is assigned to the user.
    ///   - logger: Logger use during operation
    @inlinable
    public func getRoleCredentials(
        accessToken: String,
        accountId: String,
        roleName: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> GetRoleCredentialsResponse {
        let input = GetRoleCredentialsRequest(
            accessToken: accessToken, 
            accountId: accountId, 
            roleName: roleName
        )
        return try await self.getRoleCredentials(input, logger: logger)
    }

    /// Lists all roles that are assigned to the user for a given AWS account.
    @Sendable
    @inlinable
    public func listAccountRoles(_ input: ListAccountRolesRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListAccountRolesResponse {
        try await self.client.execute(
            operation: "ListAccountRoles", 
            path: "/assignment/roles", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists all roles that are assigned to the user for a given AWS account.
    ///
    /// Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - accountId: The identifier for the AWS account that is assigned to the user.
    ///   - maxResults: The number of items that clients can request per page.
    ///   - nextToken: The page token from the previous response output when you request subsequent pages.
    ///   - logger: Logger use during operation
    @inlinable
    public func listAccountRoles(
        accessToken: String,
        accountId: String,
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListAccountRolesResponse {
        let input = ListAccountRolesRequest(
            accessToken: accessToken, 
            accountId: accountId, 
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listAccountRoles(input, logger: logger)
    }

    /// Lists all AWS accounts assigned to the user. These AWS accounts are assigned by the administrator of the account. For more information, see Assign User Access in the IAM Identity Center User Guide. This operation returns a paginated response.
    @Sendable
    @inlinable
    public func listAccounts(_ input: ListAccountsRequest, logger: Logger = AWSClient.loggingDisabled) async throws -> ListAccountsResponse {
        try await self.client.execute(
            operation: "ListAccounts", 
            path: "/assignment/accounts", 
            httpMethod: .GET, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Lists all AWS accounts assigned to the user. These AWS accounts are assigned by the administrator of the account. For more information, see Assign User Access in the IAM Identity Center User Guide. This operation returns a paginated response.
    ///
    /// Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - maxResults: This is the number of items clients can request per page.
    ///   - nextToken: (Optional) When requesting subsequent pages, this is the page token from the previous response output.
    ///   - logger: Logger use during operation
    @inlinable
    public func listAccounts(
        accessToken: String,
        maxResults: Int? = nil,
        nextToken: String? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws -> ListAccountsResponse {
        let input = ListAccountsRequest(
            accessToken: accessToken, 
            maxResults: maxResults, 
            nextToken: nextToken
        )
        return try await self.listAccounts(input, logger: logger)
    }

    /// Removes the locally stored SSO tokens from the client-side cache and sends an API call to the IAM Identity Center service to invalidate the corresponding server-side IAM Identity Center sign in session.  If a user uses IAM Identity Center to access the AWS CLI, the user’s IAM Identity Center sign in session is used to obtain an IAM session, as specified in the corresponding IAM Identity Center permission set. More specifically, IAM Identity Center assumes an IAM role in the target account on behalf of the user, and the corresponding temporary AWS credentials are returned to the client. After user logout, any existing IAM role sessions that were created by using IAM Identity Center permission sets continue based on the duration configured in the permission set. For more information, see User authentications in the IAM Identity Center User Guide.
    @Sendable
    @inlinable
    public func logout(_ input: LogoutRequest, logger: Logger = AWSClient.loggingDisabled) async throws {
        try await self.client.execute(
            operation: "Logout", 
            path: "/logout", 
            httpMethod: .POST, 
            serviceConfig: self.config, 
            input: input, 
            logger: logger
        )
    }
    /// Removes the locally stored SSO tokens from the client-side cache and sends an API call to the IAM Identity Center service to invalidate the corresponding server-side IAM Identity Center sign in session.  If a user uses IAM Identity Center to access the AWS CLI, the user’s IAM Identity Center sign in session is used to obtain an IAM session, as specified in the corresponding IAM Identity Center permission set. More specifically, IAM Identity Center assumes an IAM role in the target account on behalf of the user, and the corresponding temporary AWS credentials are returned to the client. After user logout, any existing IAM role sessions that were created by using IAM Identity Center permission sets continue based on the duration configured in the permission set. For more information, see User authentications in the IAM Identity Center User Guide.
    ///
    /// Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - logger: Logger use during operation
    @inlinable
    public func logout(
        accessToken: String,
        logger: Logger = AWSClient.loggingDisabled        
    ) async throws {
        let input = LogoutRequest(
            accessToken: accessToken
        )
        return try await self.logout(input, logger: logger)
    }
}

extension SSO {
    /// Initializer required by `AWSService.with(middlewares:timeout:byteBufferAllocator:options)`. You are not able to use this initializer directly as there are not public
    /// initializers for `AWSServiceConfig.Patch`. Please use `AWSService.with(middlewares:timeout:byteBufferAllocator:options)` instead.
    public init(from: SSO, patch: AWSServiceConfig.Patch) {
        self.client = from.client
        self.config = from.config.with(patch: patch)
    }
}

// MARK: Paginators

@available(macOS 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension SSO {
    /// Return PaginatorSequence for operation ``listAccountRoles(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listAccountRolesPaginator(
        _ input: ListAccountRolesRequest,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListAccountRolesRequest, ListAccountRolesResponse> {
        return .init(
            input: input,
            command: self.listAccountRoles,
            inputKey: \ListAccountRolesRequest.nextToken,
            outputKey: \ListAccountRolesResponse.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listAccountRoles(_:logger:)``.
    ///
    /// - Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - accountId: The identifier for the AWS account that is assigned to the user.
    ///   - maxResults: The number of items that clients can request per page.
    ///   - logger: Logger used for logging
    @inlinable
    public func listAccountRolesPaginator(
        accessToken: String,
        accountId: String,
        maxResults: Int? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListAccountRolesRequest, ListAccountRolesResponse> {
        let input = ListAccountRolesRequest(
            accessToken: accessToken, 
            accountId: accountId, 
            maxResults: maxResults
        )
        return self.listAccountRolesPaginator(input, logger: logger)
    }

    /// Return PaginatorSequence for operation ``listAccounts(_:logger:)``.
    ///
    /// - Parameters:
    ///   - input: Input for operation
    ///   - logger: Logger used for logging
    @inlinable
    public func listAccountsPaginator(
        _ input: ListAccountsRequest,
        logger: Logger = AWSClient.loggingDisabled
    ) -> AWSClient.PaginatorSequence<ListAccountsRequest, ListAccountsResponse> {
        return .init(
            input: input,
            command: self.listAccounts,
            inputKey: \ListAccountsRequest.nextToken,
            outputKey: \ListAccountsResponse.nextToken,
            logger: logger
        )
    }
    /// Return PaginatorSequence for operation ``listAccounts(_:logger:)``.
    ///
    /// - Parameters:
    ///   - accessToken: The token issued by the CreateToken API call. For more information, see CreateToken in the IAM Identity Center OIDC API Reference Guide.
    ///   - maxResults: This is the number of items clients can request per page.
    ///   - logger: Logger used for logging
    @inlinable
    public func listAccountsPaginator(
        accessToken: String,
        maxResults: Int? = nil,
        logger: Logger = AWSClient.loggingDisabled        
    ) -> AWSClient.PaginatorSequence<ListAccountsRequest, ListAccountsResponse> {
        let input = ListAccountsRequest(
            accessToken: accessToken, 
            maxResults: maxResults
        )
        return self.listAccountsPaginator(input, logger: logger)
    }
}

extension SSO.ListAccountRolesRequest: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> SSO.ListAccountRolesRequest {
        return .init(
            accessToken: self.accessToken,
            accountId: self.accountId,
            maxResults: self.maxResults,
            nextToken: token
        )
    }
}

extension SSO.ListAccountsRequest: AWSPaginateToken {
    @inlinable
    public func usingPaginationToken(_ token: String) -> SSO.ListAccountsRequest {
        return .init(
            accessToken: self.accessToken,
            maxResults: self.maxResults,
            nextToken: token
        )
    }
}
